import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {ApiProvider} from "../../providers/api/api";

/**
 * Generated class for the MessagePage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-message',
  templateUrl: 'message.html',
})
export class MessagePage {

  noticeList;
  studentId;

  // 是否存在继续授课时的padding;
  padding = 0;

  constructor(public navCtrl: NavController, public navParams: NavParams,public http:ApiProvider) {
  }

  ionViewDidLoad() {
    this.studentId=this.navParams.get("studentId");
    this.getNoticeList();
  }

  /**
   * 获取消息列表
   */
  getNoticeList()
  {
    this.http.post("/notice/queryNotice.do",{studentId:this.studentId,notice_id:null,createTime:'now',action:'up'}).subscribe(item=>{
      if(item["Code"]=="11111111")
      {
        this.http.showToast(item["Message"],'bottom');
      }
      else
      {
        this.noticeList=item["noticeList"];
      }
    })
  }

  /**
   * 下拉刷新
   * @param e
   */
  doRefresh(refresher)
  {
    this.http.post("/notice/queryNotice.do",{studentId:this.studentId,notice_id:null,createTime:'now',action:'up'}).subscribe(item=>{
      if(item["Code"]=="11111111")
      {
        this.http.showToast(item["Message"],'bottom');
      }
      else
      {
        setTimeout(() => {
          this.noticeList=item["noticeList"];
          refresher.complete();
        },200);
      }
    })
  }
}
